<template>
  <div>
      <el-form
        label-position="right"
        ref="form"
        :model="form"
        :rules="formRules"
        label-width="100px"
      >
        <!-- <el-row v-for="(subModule, index) in data" :key="index"
          >{{ subModule[0] }}:
          <el-checkbox-group v-if="index == 1" v-model="form.defining_feature">
            <el-col :span="4" v-for="(item,i) in subModule" :key="i">
              <el-checkbox v-if="i!=0" :label="item">{{ item[0] }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 2" v-model="form.risk_group">
            <el-col :span="4" v-for="(item,i) in subModule" :key="i">
              <el-checkbox v-if="i!=0" :label="item">{{ item[0] }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 3" v-model="form.risk_factor">
             <el-col :span="4" v-for="(item,i) in subModule" :key="i">
              <el-checkbox v-if="i!=0" :label="item">{{ item[0] }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 4" v-model="form.relevant_factor">
             <el-col :span="4" v-for="(item,i) in subModule" :key="i">
              <el-checkbox v-if="i!=0" :label="item">{{ item[0] }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 5" v-model="form.evidence">
             <el-col :span="4" v-for="(item,i) in subModule" :key="i">
              <el-checkbox v-if="i!=0" :label="item">{{ item[0] }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
        </el-row> -->
        <el-row v-for="(subModule, index) in data" :key="index"
          > <span  v-if="index != 0">{{ subModule[0]}}:</span>
          <el-checkbox-group v-if="index != 0" v-model="form.data">
            <el-col :span="4" v-for="(item,i) in subModule" :key="i">
              <el-checkbox v-if="i!=0" :label="item">{{ item[0] }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
        </el-row>
      </el-form>
  </div>
</template>

<script>
var BaaS = require("minapp-sdk");
let clientID = "9ed0a3da89683e42d793";
BaaS.init(clientID);
export default {
  name: "activity",
  props: {
    module_activity: {
      type: String,
      default: "",
    },
    data:{
      type: Array,
      default:[],
    }
  },
  data() {
    return {
      subModuleList: [
        "定义性特征",
        "危险人群",
        "危险因素",
        "相关因素",
        "循证知识",
      ],
      subModuleListSet: new Set(),
      subModuleItemList: [
        [
          "步态改变",
          "从事替换动作",
          "粗大运动技能下降",
          "短暂偏执",
          "短暂眼球震颤",
          "对环境不满意",
          "对难以维持责任内疚",
          "对睡眠不满意",
          "对休息的需要增加",
          "对周围环境无兴趣",
          "翻身困难",
          "反应时间延长",
          "非恢复性睡眠型态",
          "非自主觉醒",
          "功能性能力下降",
          "好斗",
          "昏昏欲睡",
          "昏睡",
          "活动不协调",
          "活动范围减少",
          "活动缓慢",
          "活动痉挛",
          "活动时心率异常",
          "活动时血压异常",
          "活动性震颤",
          "精细运动技能下降",
          "冷漠",
          "内省",
          "疲乏",
          "疲劳",
          "频繁小睡",
          "情感减少",
          "躯体功能失调",
          "全身乏力",
          "缺乏精力",
          "日常功能活动困难",
          "食欲下降",
          "手震颤",
          "睡眠型态改变",
          "疼痛敏感性增加",
          "维持日常生活的能力受损",
          "维持睡眠困难",
          "维持正常躯体活动的能力受损",
          "萎靡",
          "无聊",
          "无休息感",
          "心电图（ECG）异常",
          "性欲改变",
          "言语减少",
          "运动性不适",
          "运动性呼吸困难",
          "姿势不稳定",
          "组织破坏",
          "组织受损",
        ],
        [
          "暴露于高压电源",
          "负性生活事件暴露",
          "既往活动不耐受史",
          "家族性睡眠瘫痪症",
          "苛刻的职业",
          "长期制度化",
          "长期住院",
        ],
        [
          "供氧/需氧失衡",
          "活动缺乏经验",
          "静坐的生活方式",
          "移动障碍",
          "营养不良",
        ],
        [
          "BMI＞第75个百分点（同年龄同性别）",
          "不愿意开始活动",
          "持续节律不同步",
          "持续睡眠卫生不良",
          "当前的情况不允许从事活动",
          "动机不足",
          "非刺激性生活方式",
          "关节僵硬",
          "关于可接受活动的文化信念",
          "活动不耐受",
          "肌力下降",
          "肌肉控制下降",
          "肌肉质量下降",
          "精力缺乏",
          "梦游",
          "耐力下降",
          "年龄相关的睡眠时相改变",
          "强体力活动增加",
          "缺乏保护组织完整性的知识",
          "缺乏躯体活动意义的知识",
          "缺乏维持组织完整性的知识",
          "日均躯体活动量低于同性别和同年龄推荐的活动量",
          "深夜精神错乱",
          "失用",
          "睡眠剥夺",
          "夜惊",
          "移动阻碍",
          "营养状况失衡",
          "娱乐活动缺乏",
          "与环境相关的过度刺激",
          "与环境相关的支持不足",
          "与环境相关的阻碍",
          "长期不适",
          "制动",
        ],
        [
          "发作性睡病",
          "感知觉受损",
          "骨骼肌受损",
          "骨骼结构完整性改变",
          "呼吸性疾病",
          "挛缩",
          "手术操作",
          "睡眠呼吸暂停",
          "睡眠同伴引起的干扰",
          "睡眠相关性痛性勃起",
          "睡眠相关遗尿",
          "循环问题",
          "医嘱限制活动",
          "医嘱制动",
          "原发性中枢神经系统性过度嗜睡",
          "治疗性隔离",
          "周期性肢体运动性疾病",
          "周围神经病变",
        ],
      ],
      submoduleItemListSet: new Set(),
      form: {
        data:[]
      },
      formRules: {},
    };
  },
  methods: {
    getSubModule(index) {
      let query = new BaaS.Query();
      let overall_eval = new BaaS.TableObject("overall_eval_item");
      query.compare("module", "=", this.module_activity);
      overall_eval
        .setQuery(query)
        .select(["module", "submodule"])
        .limit(1000)
        .offset(index)
        .find()
        .then((res) => {
          let datas = res.data.objects;
          datas.forEach((data) => {
            this.subModuleListSet.add(data.submodule);
          });
          if (res.data.meta.next !== null) {
            this.getSubModule(index + 1000);
          } else {
            this.subModuleList = Array.from(this.subModuleListSet);
            console.log(this.subModuleList);
          }
        });
    },
    getSubModuleItem(index) {
      for (let i = 0; i < this.subModuleList.length; i++) {
        let itemSet = new Set();
        // this.subModuleItemList[i] = []; //将当前数组的元素设置为数组就是二维数组了
        let query = new BaaS.Query();
        let overall_eval = new BaaS.TableObject("overall_eval_item");
        query.compare("module", "=", this.module_activity);
        query.compare("submodule", "=", this.subModuleList[i]);
        overall_eval
          .setQuery(query)
          .select(["submodule", "item"])
          .limit(1000)
          .offset(index)
          .find()
          .then((res) => {
            let datas = res.data.objects;
            datas.forEach((data) => {
              itemSet.add(data.item);
            });
            if (res.data.meta.next !== null) {
              this.getSubModuleItem(index + 1000);
            } else {
              this.subModuleItemList.push(Array.from(itemSet));
            }
          });
      }
      console.log(this.subModuleItemList);
    },
    init() {
      this.getSubModule(0);
      this.getSubModuleItem(0);
    },
  },
  mounted() {
    // this.init();
    
  },
};
</script>
<style lang="less" scoped>
</style>